﻿function enemy_0(ex, ey, escript) {
    enemy[enemy.length] = {x: ex, y: ey, v: 0, ang: 0, hp: 10, 
                            script: escript, script_time: 0,
                            die: enemy_die_0,
                            draw: enemy_draw_0, draw_time: 0};
}

function enemy_draw_0() {
    if (this.draw_time >= 18)
        this.draw_time = 0;
    var index = floor(this.draw_time / 6);
    this.draw_time++;
    context.drawImage(enemy_img[0], enemy_imgx[0][index], enemy_imgy[0][index], 32, 32, this.x - 16, this.y - 16, 32, 32);
}

function enemy_die_0() {
    item_0(this.x, this.y);
    item_1(rang(20) + this.x, rang(20) + this.y);
    effect_0(this.x, this.y);
}

function enemy_update() {
    var i = enemy.length;
    while (i--) {
        if (enemy[i].hp <= 0) {
            enemy[i].die();
            enemy_remove(i);
            continue;
        }
        
        enemy[i].script(enemy[i]);
    
        if (enemy[i].x < -20 || enemy[i].x > WIDTH + 20 || 
            enemy[i].y < -20 || enemy[i].y > HEIGHT + 20) {
            enemy_remove(i);
            continue;
        }
    }
}

function enemy_draw() {
    var i = enemy.length;
    while (i--) {
        enemy[i].draw();
    }
}

function enemy_remove(i) {
    enemy.splice(i, 1);
}
